package com.androidhive.xmlparsing;

import java.util.ArrayList;
import java.util.HashMap;
 
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DealListViewAdapter extends BaseAdapter {
	
	 private Activity activity;
	    private ArrayList<HashMap<String, String>> data;
	    private static LayoutInflater inflater=null;
	    public DealListViewAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
	        activity = a;
	        data=d;
	        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    }
	    
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		 return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 	View vi=convertView;
	        if(convertView==null)
	            vi = inflater.inflate(R.layout.list_item, null);
	 
	        TextView name = (TextView)vi.findViewById(R.id.name);
	        TextView desciption = (TextView)vi.findViewById(R.id.desciption);
	        TextView cost = (TextView)vi.findViewById(R.id.cost);
	        HashMap<String, String> item = new HashMap<String, String>();
	        item = data.get(position);
	 
	        //Setting all values in listview
	        name.setText(item.get("title"));
	        desciption.setText(item.get("city"));
	        cost.setText(item.get("dealPrice"));
	        return vi;
	    }

}
